// 药房管理
<template comments>
  <div class="pharmacy">
    <TopManu :stprageStatus="6" @handcreate="handcreate"></TopManu>
  
    <div class="search">
      <div class="s1">
        <el-input
          v-model="params.check_user"
          placeholder="请输入审核人姓名"
        ></el-input>
         <el-input
          v-model="params.create_by"
          placeholder="请输入制单人姓名"
        ></el-input>
        <el-button @click="searchB()" class="butB_Sel">查询</el-button>
        <el-button @click="resetSearchB()"  class="butB_Reset">重置</el-button>
         <el-button @click="add()" class="butB_Add">新增</el-button>
      </div>
      <div class="selectBai">
        <div>
          <el-select v-model="params.store_id" placeholder="库房" @change="searchB">
            <el-option
              v-for="item in  KuFangList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
        <div>
          <el-select v-model="params.status" placeholder="状态" @change="searchB">
            <el-option
              v-for="item in  $baseBai['drugRetreat']['status']"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
          <div>
          <el-select v-model="params.house_id" placeholder="退领药房" @change="searchB">
            <el-option
              v-for="item in  houseList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
        <div>
          <el-date-picker
           @change="searchB"
            v-model="params.start_time"
            type="daterange"
            value-format="yyyy-MM-dd"
            start-placeholder="制单日期"
            end-placeholder="制单日期"
          >
          </el-date-picker>
        </div>
      </div>
    </div>

    <div class="tablesB">
      <el-table  v-loading="params.loading" :data="data" border >
        <el-table-column type="index" width="70" label="序号">
        </el-table-column>
        <template v-for="(item, index) in $baseBai['drugRetreat']['list']">

             <el-table-column :width="item.width" v-if="item.prop == 'status'" :prop="item.prop" :label="item.label" :key="index">
                        <template slot-scope="scope">
                            <div v-if="scope.row.status">{{ $baseBai['drugRetreat']['status'][scope.row.status-1].label }}</div>
                        </template>
              </el-table-column>
            <el-table-column  v-else  :width="item.width" :prop="item.prop" :label="item.label" :key="index+item"> </el-table-column>
           </template>
            <el-table-column label="更多" width="150" fixed="right"    >
              <template slot-scope="scope">
                <el-dropdown
                  class="tableMore"
                  split-button
                  
                  type="primary"
                  size="12"
                  @command="handleClick"
                
                >
                  更多
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item :command="scope.row" type="1" >修改</el-dropdown-item>
                    <el-dropdown-item :command="scope.row" type="2" >删除</el-dropdown-item>
                    <el-dropdown-item :command="scope.row" type="3">审核</el-dropdown-item>
                    <el-dropdown-item :command="scope.row" type="4" >驳回</el-dropdown-item>
                    <el-dropdown-item :command="scope.row" type="7" >接收</el-dropdown-item>
                    <el-dropdown-item :command="scope.row" type="5" >详情</el-dropdown-item>
                    <el-dropdown-item :command="scope.row" type="6" >打印</el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
             
                
              </template>
            </el-table-column>
      
      </el-table>
        <div>
           <el-pagination
           class="fenye"
            :background="true"
            :current-page="params.page"
            :page-size="params.limit"
            layout="prev, pager, next"
            @current-change="handlePagination"
            :total="params.pageCount">
            </el-pagination>
      </div>
    </div>


      <el-dialog
        :title="dialogTitle"
        :visible.sync="Detail_Show"
         :close-on-click-modal="false"
        width="30%"
        v-if="Detail_Show"
        :destroy-on-close="true"
        :before-close="()=>{this.Detail_Show=!this.Detail_Show}">
             <Detail :dialogTitle='dialogTitle' :thatF="this"></Detail>
      
      </el-dialog>
  </div>
</template>

<script>
let t;
import Detail from './common/detail'
import TopManu from "@/components/TopMenu";
import { mapState,mapActions } from "vuex";
// getDict_dataKuFangList
export default {
  name:"drugRetreat",
  data() {
    return {
      Detail_Show:false,
      tableTitle: [],
      dialogTitle:'',
      params: {
        loading:false, 
        tabIndex: "1",
        page:1,
        limit:10,
        store_id:'',
        status: "",
        house_id:'',
        check_user: "",
        create_by:'',
        start_time: "",
         pageCount:0,
      },
      
    
      data: [],
    };
  },
  components: {
    TopManu,
    Detail,
  },
  computed: {
    ...mapState({
      KuFangList: state => state.dictBai.KuFangList,
      houseList:state => state.dictBai.houseList,
      drugCollarDetail:state => state.storage.drugCollarDetail,
    }),
  },
  mounted() {
    t = this;

     if(t.KuFangList.length==0){
        t['dictBai/getDict_dataKuFangList']({})
    }
       if(t.houseList.length==0){
        t['dictBai/getDrug_houseIndex']({})
       }
    
      t.getList()
   
  },
  methods: {
     ...mapActions([
         'dictBai/getDict_dataKuFangList',
         'dictBai/getDrug_houseIndex',
         'storage/getdrug_houseExitClaimShow',
         'storage/emptyData',
        
    ]),
     resetSearchB(){
       this.params={
         loading:false, 
        tabIndex: "1",
        page:1,
        limit:10,
        store_id:'',
        status: "",
        house_id:'',
        check_user: "",
        create_by:'',
        start_time: "",
         pageCount:0,
      } 
      this.getList()
     },
       add(){
        t['storage/emptyData']().then(res=>{
           this.Detail_Show=!this.Detail_Show;
           t.dialogTitle='药品退领新增'
        })
       
        
      },
       handleClick(...item){
       
           console.log(item)
          switch (item[1].$attrs.type) {
            case '1':
                
                         t['storage/getdrug_houseExitClaimShow']({id:item[0].id}).then(res=>{
                        if(res.code==200)
                        { t.dialogTitle='药品退领修改';
                           this.Detail_Show=!this.Detail_Show;
                        }
                      })
              break;
            case '2':

                   this.$confirm('是否删除单号'+item[0].number+'？', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
                }).then(() => {
                      t['_API'].getdrug_houseExitClaimDel({id:item[0].id}).then(res=>{
                        if(res.code==200) {
                             this.$message({
                                    message: res.message,
                                    type: 'success'
                                });
                                t.searchB()
                        }
                      })

                    
                })   
          
              break;
              case '3':
              
                    this.$confirm('是否审核单号'+item[0].number+'？', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
                }).then(() => {
                      t['_API'].getdrug_houseExitClaimCheck({id:item[0].id,type:1}).then(res=>{
                        if(res.code==200) {
                             this.$message({
                                    message: res.message,
                                    type: 'success'
                                });
                                t.searchB()
                        }
                      })

                    
                })   
          
              break;
               case '4':
              
                    this.$confirm('是否驳回单号'+item[0].number+'？', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
                }).then(() => {
                      t['_API'].getdrug_houseExitClaimCheck({id:item[0].id,type:2}).then(res=>{
                        if(res.code==200) {
                             this.$message({
                                    message: res.message,
                                    type: 'success'
                                });
                                t.searchB()
                        }
                      })

                    
                })   
          
              break;
             case '5':

                
                t['storage/getdrug_houseExitClaimShow']({id:item[0].id}).then(res=>{
                if(res.code==200){
                 
                    t.dialogTitle='药品退领详情';
                     t.Detail_Show=!t.Detail_Show;
                   
                }
               })
               
              break;
             case '7':
              
                    this.$confirm('是否接收单号'+item[0].number+'？', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
                }).then(() => {
                      t['_API'].getdrug_houseExitClaimAccept({id:item[0].id}).then(res=>{
                        if(res.code==200) {
                             this.$message({
                                    message: res.message,
                                    type: 'success'
                                });
                                t.searchB()
                        }
                      })

                    
                })   
          
              break;
            default:
              break;
          }
      },
      handcreate(num){
          let url='';
          console.log("num",num)
            switch (num) {
            case 1:
                  url='purchaseApply'
              break;
            case 2:
               url='purchasePlan'
                break;
             case 3:
               url='enterManage'
                break;
             case 4:
               url='outManage'
                break;
              case 5:
               url='drugCollar'
                break;
             case 6:
               url='drugRetreat'
                break;
             case 7:
               url='drugInspect'
                break;
            default:
              break;
            }
         this.$router.push({name:url})
      },
  
  
    
    searchB() {
     
      t.params.page=1;
      t.getList()
    },

 
     handlePagination(e){
       
         t.params.page=e;
        t.getList()
        
    },
    getList(){
     
      let d={
       
        limit:t.params.limit,
        page:t.params.page,
        status:t.params.status,
        time:this.params.start_time?((this.params.start_time.toString()).replace(',','|')).toString():'',
        check_user:t.params.check_user,
        create_by:t.params.create_by,
        store_id:t.params.store_id,
        house_id:t.params.house_id,
         
      }
      t.data=[];
       this.params.loading=true;
      this['_API'].getdrug_houseExitClaimIndex(d).then(res=>{
         this.params.loading=false;
                 if(res.code==200){
                   
                     
                        this.data=res.data.list;
                        this.params.pageCount =res.data.count;
                       
                 }
      })
      
    },
  },
};
</script>

<style lang="scss" scoped>
/deep/ .el-tabs__nav {
  
  .el-tabs__item {
    border-bottom: 1px solid #e4e7ed;
  }
  .is-active {
    color: #02bf6b;
  }
  .el-tabs__item:hover {
    color: #02bf6b;
  }
}
.search {
  border: 1px solid #f2f2f2;
  margin: 10px 2%;
  padding: 20px;
  border-radius: 10px;
  .s1 {
    width: 600px;
    display: flex;
    .el-input{
      margin-right: 10px;
    }
    button {
      margin-left: 20px;
      margin-bottom: 20px;
      color: white;
    }
  }
  .selectBai {
    display: flex;
    > div {
      margin-right: 10px;
    }
  }
}

.tableMore {
  /deep/ .el-button--primary {
    color: black;
    background-color: initial;
    border-color: #e2e2e2;
  }
}
.tablesB,.tabsB{margin: 20px 2% 0;}

  .fenye{
    text-align: right;
    margin-top: 20px;   
    
  }
  /deep/ .el-pagination.is-background .el-pager li:not(.disabled).active{
      background-color: #02bf6b;
  }

  
  /deep/ .el-dialog__body {
  height: 70vh;
  overflow: scroll;
}
/deep/ .el-dialog{
        width: 80% !important;
  }
</style>